from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QSlider
from PyQt5.QtGui import QPixmap
from PyQt5.QtCore import Qt

class MyApp(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        # 创建水平滑块
        sld = QSlider(Qt.Horizontal, self)
        sld.setFocusPolicy(Qt.NoFocus)
        sld.setGeometry(30, 40, 100, 30)
        sld.valueChanged[int].connect(self.changeValue)

        # 创建标签用于显示图片
        self.label = QLabel(self)
        self.label.setGeometry(250, 40, 250, 250)  # 调整标签大小

        # 设置窗口属性
        self.setGeometry(300, 300, 700, 700)
        self.setWindowTitle('QSlider')
        self.show()

    def changeValue(self, value):
        # 根据滑块的值设置图片
        if value == 0:
            self.setImage('mute.png')
        elif 0 < value <= 30:
            self.setImage('min.png')
        elif 30 < value < 80:
            self.setImage('med.png')
        else:
            self.setImage('max.png')

    def setImage(self, image_path):
        # 加载图片并设置到标签
        pixmap = QPixmap(image_path)
        if not pixmap.isNull():
            self.label.setPixmap(pixmap)
        else:
            print(f"Failed to load image: {image_path}")

if __name__ == "__main__":
    app = QApplication([])
    window = MyApp()
    app.exec_()